<?php
namespace App\Service\Quote;

use App\Models\Inquiry\InquirySheet;
use App\Models\Quote\Quotation;
use App\Service\Inquiry\InquiryService;

class QuoteService
{
    public static function create($request,$inquiry_sheet,$user)
    {
        return Quotation::create([
            'no' => self::generateNo($user->id),
            'inquiry_sheet_id' => $inquiry_sheet->id,
            'inquiry_uid' => $inquiry_sheet->uid,
            'quote_uid' => $user->uid,
            'status' => 1,
            'goods_id' => $inquiry_sheet->goods_id,
            'number' => $inquiry_sheet->number,
            'price' => $request->price
        ]);
    }

    public static function generateNo($id)
    {
        return time().$id;
    }

    public static function quoteList($uid,$status)
    {
        return InquirySheet::where([
            'quote_uid' => $uid,
            'status' => $status
        ])->orderBy('id','desc')->with('quotation')->paginate(20);
    }
}